package com.biboheart.adapter.express.support;

import com.biboheart.adapter.express.operation.LogicalRegistry;
import com.biboheart.adapter.express.operation.LogicalService;
import com.biboheart.adapter.support.enums.LogicalEnum;

public class DefaultLogicalService extends GenericLogicalService{
    private static volatile DefaultLogicalService sharedInstance;

    public DefaultLogicalService() {addOperator(this);}

    public static LogicalService getSharedInstance() {
        DefaultLogicalService ls = sharedInstance;
        if (null == ls) {
            synchronized (DefaultLogicalService.class) {
                ls = sharedInstance;
                if (ls == null) {
                    ls = new DefaultLogicalService();
                    sharedInstance = ls;
                }
            }
        }
        return ls;
    }

    public static void addOperator(LogicalRegistry logicalRegistry) {
        logicalRegistry.addLogical(LogicalEnum.OPERATOR_LOGICAL_AND.code(), new LogicalAndCalculate());
        logicalRegistry.addLogical(LogicalEnum.OPERATOR_LOGICAL_OR.code(), new LogicalOrCalculate());
        logicalRegistry.addLogical(LogicalEnum.OPERATOR_LOGICAL_NOT.code(), new LogicalNotCalculate());
        logicalRegistry.addLogical(LogicalEnum.OPERATOR_LOGICAL_GREATER.code(), new LogicalGreaterCalculate());
        logicalRegistry.addLogical(LogicalEnum.OPERATOR_LOGICAL_GREATER_EQUAL.code(), new LogicalGreaterEqualCalculate());
        logicalRegistry.addLogical(LogicalEnum.OPERATOR_LOGICAL_LESS.code(), new LogicalLessCalculate());
        logicalRegistry.addLogical(LogicalEnum.OPERATOR_LOGICAL_LESS_EQUAL.code(), new LogicalLessEqualCalculate());
        logicalRegistry.addLogical(LogicalEnum.OPERATOR_LOGICAL_EQUAL.code(), new LogicalEqualCalculate());
        logicalRegistry.addLogical(LogicalEnum.OPERATOR_LOGICAL_EQUAL_NOT.code(), new LogicalEqualNotCalculate());
    }
}
